import unittest
from alg import Solution
from gen import get_sample_case, generate_test_case

class TestMaxArea(unittest.TestCase):
    def test_sample_case(self):
        sol = Solution()
        sample_case = get_sample_case()
        result = sol.maxArea(sample_case)
        print(f"示例测试用例 {sample_case} 的最大盛水量为: {result}")
        self.assertEqual(result, 49)

    def test_random_cases(self):
        sol = Solution()
        # 测试多个随机生成的用例
        for _ in range(10):
            test_case = generate_test_case()
            expected = self.brute_force_max_area(test_case)
            result = sol.maxArea(test_case)
            print(f"随机测试用例 {test_case} 的最大盛水量为: {result}")
            self.assertEqual(result, expected)

    def brute_force_max_area(self, height: list[int]) -> int:
        """暴力解法用于验证结果"""
        max_water = 0
        for i in range(len(height)):
            for j in range(i + 1, len(height)):
                current = min(height[i], height[j]) * (j - i)
                if current > max_water:
                    max_water = current
        return max_water

if __name__ == '__main__':
    unittest.main()